package com.example.neusoft.yuejian_12.Activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.neusoft.yuejian_12.Adapter.UserPhotoListAdapter;
import com.example.neusoft.yuejian_12.JavaBean.Photo;
import com.example.neusoft.yuejian_12.Listener.UserPhotoListener;
import com.example.neusoft.yuejian_12.Model.UserModel;
import com.example.neusoft.yuejian_12.R;

import java.util.List;

public class UserPhotoActivity extends AppCompatActivity {
    private List<Photo> list;
    private RecyclerView recyclerView;
    private String userid;
    private String user_photo;
    private String user_name;
    private ImageView user_pic;
    private Context context;
    private ImageView collectlist_return;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_photo);
        initViews();
        initEvents();
        getUserId();
        UserCollectList();
    }

    private void initViews(){
        recyclerView = (RecyclerView) findViewById(R.id.user_photo_rv);
        collectlist_return= (ImageView) findViewById(R.id.user_photo_back);
    }

    private void initEvents(){
        collectlist_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        context= UserPhotoActivity.this;
    }

    private void UserCollectList() {
        UserModel userModel = new UserModel();
        userModel.getShaituByUser(userid,usercollectListener);
    }

    UserPhotoListener usercollectListener=new UserPhotoListener() {
        @Override
        public void onResponse(List<Photo> stringBean) {
            list = stringBean;
            LinearLayoutManager manager=new LinearLayoutManager(context);
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(manager);
            recyclerView.setItemAnimator(new DefaultItemAnimator());
            recyclerView.setAdapter(new UserPhotoListAdapter(UserPhotoActivity.this,list,userid));
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(UserPhotoActivity.this, "获取失败", Toast.LENGTH_SHORT).show();
        }
    };

    private void getUserId(){
        userid = getApplication().getSharedPreferences("userInfo", Context.MODE_PRIVATE).getString("user_id", String.valueOf(0));
        Log.v("userphoto获取用户id", String.valueOf(userid));
    }
}
